GtkStyle: Listen to context changes.
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 3 Nov 2010 11:18:48 +0000 (12:18 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Sat, 4 Dec 2010 14:38:36 +0000 (15:38 +0100)
This way the GtkStyle is updated to the latest style info, actually
emitting ::style-set must be performed after invalidating the style
context.

gtk/gtkstyle.c

index 5b0721e1f01cda7a28971ff174d6a2e30228469c..6c4530261b33cdb8a2bf11c8b2405e541bdd56b6 100644 (file)
@@ -79,6 +79,7 @@ typedef struct _GtkStylePrivate GtkStylePrivate;
 struct _GtkStylePrivate {
   GSList *color_hashes;
   GtkStyleContext *context;
+  gulong context_changed_id;
 };
 
 enum {
@@ -610,7 +611,12 @@ gtk_style_finalize (GObject *object)
     g_object_unref (style->rc_style);
 
   if (priv->context)
-    g_object_unref (priv->context);
+    {
+      if (priv->context_changed_id)
+        g_signal_handler_disconnect (priv->context, priv->context_changed_id);
+
+      g_object_unref (priv->context);
+    }
 
   G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
 }
@@ -735,6 +741,13 @@ gtk_style_update_from_context (GtkStyle *style)
     }
 }
 
+static void
+style_context_changed (GtkStyleContext *context,
+                       gpointer         user_data)
+{
+  gtk_style_update_from_context (GTK_STYLE (user_data));
+}
+
 static void
 gtk_style_constructed (GObject *object)
 {
@@ -746,7 +759,8 @@ gtk_style_constructed (GObject *object)
     {
       gtk_style_update_from_context (GTK_STYLE (object));
 
-      /* FIXME: Listen to context changes */
+      priv->context_changed_id = g_signal_connect (priv->context, "changed",
+                                                   G_CALLBACK (style_context_changed), object);
     }
 }